package com.googlecode.scup.grammar.grammarspart;

import java.util.List;

public class Production {
    private List<Symbol> production;

    public Production(List<Symbol> production) {
        this.production = production;
    }

    public Symbol getSymbol(int index) {
        if (index >= production.size()) {
            return null;
        }
        return production.get(index);
    }

    public void addSymbol (Symbol s) {
    	production.add(s);
    }

    public List<Symbol> getProduction() {
        return production;
    }

    public int size() {
        return production.size();
    }

    public String toString() {
        StringBuilder result = new StringBuilder();
        for (Symbol sym : production) {
            result.append(' ');
            result.append(sym.getName());
        }
        return result.toString();
    }

    public boolean equals(Object obj) {
        if (! (obj instanceof Production)) {
			return false;
		}
		Production prod = (Production) obj;
		if (this.production.size() != prod.size()) return false;
        for (int i = 0; i < this.production.size(); ++i) {
            if (! this.production.get(i).equals(prod.production.get(i))) return false;
        }
        return true;
    }
}
